package com.ysd.lis.controller.sys;


import com.ysd.common.Result;
import com.ysd.lis.annotation.LogDetail;
import com.ysd.lis.aspect.OperationType;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.SysOrgDepartment;
import com.ysd.lis.request.FindDeptartmentNamesParam;
import com.ysd.lis.request.OrgDepartmentParam;
import com.ysd.lis.service.SysOrgDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * cold_chain.t_org_department 前端控制器
 * </p>
 *
 * @author Peng
 * @since 2021-10-08
 */
@Api(tags = "部门管理")
@RestController
@RequestMapping("/api/sys")
public class SysOrgDepartmentController extends BaseController {
    @Autowired
    SysOrgDepartmentService sysOrgDepartmentService;

    @ApiOperation("添加部门")
    @PostMapping("/addDepartment")
    @LogDetail(requestParam = "addDepartment", operationType = OperationType.INSERT, module = "科室管理", content = "添加科室操作")
    public Result addDepartment(@RequestBody SysOrgDepartment sysOrgDepartment) {
        sysOrgDepartment.setDelFlag(0);
        return sysOrgDepartmentService.addDepartment(sysOrgDepartment);
    }

    @ApiOperation("修改部门")
    @PostMapping("/editDepartment")
    @LogDetail(requestParam = "editDepartment", operationType = OperationType.UPDATE, module = "科室管理", content = "修改科室操作")
    public Result editDepartment(@RequestBody SysOrgDepartment sysOrgDepartment) {
        return sysOrgDepartmentService.editDepartment(sysOrgDepartment);
    }

    @ApiOperation("删除部门")
    @DeleteMapping("/deleteDepartment/{id}")
    @LogDetail(requestParam = "deleteDepartment", operationType = OperationType.DELETE, module = "科室管理", content = "删除科室操作")
    public Result deleteDepartment(@PathVariable("id") String id) {
        SysOrgDepartment sysOrgDepartment = new SysOrgDepartment();
        sysOrgDepartment.setId(id);
        sysOrgDepartment.setDelFlag(1);
        return sysOrgDepartmentService.deleteDepartment(sysOrgDepartment);
    }

    @ApiOperation("根据机构获取部门")
    @GetMapping("/findDepartmentList")
    public Result findDepartmentList(OrgDepartmentParam orgDepartmentParam) {
        return sysOrgDepartmentService.findDepartmentList(orgDepartmentParam);
    }
    @ApiOperation("根据机构获取部门")
    @GetMapping("/findSysOrgDepartmentList")
    public Result findSysOrgDepartmentList(OrgDepartmentParam orgDepartmentParam) {
        return sysOrgDepartmentService.findSysOrgDepartmentList(orgDepartmentParam);
    }

    @ApiOperation("根据机构获取部门")
    @GetMapping("/findDeptTree")
    public Result findDeptTree(OrgDepartmentParam orgDepartmentParam) {
        return sysOrgDepartmentService.findDeptTree(orgDepartmentParam);
    }

    @ApiOperation("根据机构获取部门")
    @GetMapping("/findDepartmentUserListByOrgId")
    public Result findDepartmentUserListByOrgId(OrgDepartmentParam orgDepartmentParam) {
        return sysOrgDepartmentService.findDepartmentUserListByOrgId(orgDepartmentParam);
    }

    @ApiOperation("根据科室编号获取科室名称，仅用于显示")
    @GetMapping("/fingDepartmentNamesByCodes")
    public Result fingDepartmentNamesByCodes(FindDeptartmentNamesParam input) {
        return sysOrgDepartmentService.fingDepartmentNamesByCodes(input);
    }

    @ApiOperation("根据机构获取部门")
    @GetMapping("/getDepartmentList")
    public Result getDepartmentList(OrgDepartmentParam orgDepartmentParam) {
        return sysOrgDepartmentService.getDepartmentList(orgDepartmentParam);
    }
    @ApiOperation("根据授权机构获取部门")
    @GetMapping("/getDepartAuthorizementList")
    public Result getDepartAuthorizementList(OrgDepartmentParam orgDepartmentParam) {
        return sysOrgDepartmentService.getDepartAuthorizementList(orgDepartmentParam);
    }

    @ApiOperation("根据当前登录用户获取部门")
    @GetMapping("/findDepartmentListbyCurrentUserOrg")
    public Result findDepartmentListByCurrentUserOrg() {
        return sysOrgDepartmentService.findDepartmentListByCurrentUserOrg();
    }

    @ApiOperation("同步科室")
    @GetMapping("/syncOrgDepartments")
    public Result syncOrgDepartments() {
        return sysOrgDepartmentService.syncOrgDepartments();
    }

}
